package com.example.sm.mycook.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.sm.mycook.R;
import com.example.sm.mycook.beans.HomeComboBean;

import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */
public class HomeComboAdapter extends BaseAdapter {

    private Context context;
    private List<HomeComboBean.DataBean> list;

    public HomeComboAdapter(Context context, List<HomeComboBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder=null;
        if (convertView==null)
        {
            convertView= LayoutInflater.from(context).inflate(R.layout.home_combo_lv_item,parent,false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(list.get(position).getUrl()).into(viewHolder.combo_iv);
        viewHolder.combo_pName.setText(list.get(position).getPName());
        viewHolder.combo_price.setText("套餐价："+"￥"+list.get(position).getPrice());
        viewHolder.combo_detail.setText(list.get(position).getMaterialName());

        return convertView;
    }

    class ViewHolder
    {
        ImageView combo_iv;
        TextView combo_pName,combo_price,combo_detail;
        public ViewHolder(View itemView)
        {
            combo_iv= (ImageView) itemView.findViewById(R.id.home_combo_lv_iv);
            combo_pName= (TextView) itemView.findViewById(R.id.home_combo_lv_pName);
            combo_price= (TextView) itemView.findViewById(R.id.home_combo_lv_price);
            combo_detail= (TextView) itemView.findViewById(R.id.home_combo_lv_detail);

        }
    }
}
